package com.getpebble.android.common.provider.model;

import android.content.ContentResolver;
import android.content.Context;
import android.content.CursorLoader;
import android.database.Cursor;
import android.net.Uri;
import com.getpebble.android.common.core.util.PblContentProviderUtil;
import com.getpebble.android.common.model.PblDataModel;
import com.getpebble.android.common.model.PblDevice;

public class PblInstalledJoinLockerAppDataModel extends PblDataModel {
    private static final String[] PROJECTION_ALL_FIELDS = new String[]{"installed_apps.uuid", "installed_apps._id", "installed_apps.app_name", "installed_apps.company_name", "installed_apps.capabilities", "installed_apps._date_created", "locker_apps._id AS locker_id", "locker_apps.app_id", "locker_apps.title", "locker_apps.author", "locker_apps.description", "locker_apps.developer_id", "locker_apps.icon_image", "locker_apps.preview_image", "locker_apps.screenshot_image", "locker_apps.add_link", "locker_apps.remove_link", "locker_apps.version AS locker_version", "installed_apps.version AS installed_version", "locker_apps.companion_icon", "locker_apps.companion_name", "locker_apps.companion_url", "locker_apps.companion_id", "locker_apps.add_link", "locker_apps.remove_link", "locker_apps.version AS locker_version", "installed_apps.version AS installed_version", "locker_apps.pbw_file"};
    public static final Uri TABLE_URI = PblContentProviderUtil.getTableUri(getJoinedTableName());

    public static String getJoinedTableName() {
        return "installed_apps LEFT OUTER JOIN locker_apps ON installed_apps.uuid = locker_apps.uuid";
    }

    public static CursorLoader fetchApps(Context context, PblDevice device) {
        String[] selectionArgs = new String[]{device.getAddress()};
        return new CursorLoader(context, TABLE_URI, PROJECTION_ALL_FIELDS, "installed_apps.device_address = ?", selectionArgs, "installed_apps.bank_number ASC");
    }

    public static Cursor fetchAppsCursor(ContentResolver contentResolver, PblDevice device) {
        String[] selectionArgs = new String[]{device.getAddress()};
        return contentResolver.query(TABLE_URI, PROJECTION_ALL_FIELDS, "installed_apps.device_address = ?", selectionArgs, "installed_apps.bank_number ASC");
    }
}
